package com.lqs.dataservice.Service;

import com.lqs.dataservice.constants.MessageConstants;
import com.lqs.dataservice.dao.ArmyDao;
import com.lqs.dataservice.entity.Army;
import com.nip.db.mongodb.utils.tips.Response;
import com.nip.db.mongodb.utils.tips.ResponseCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ArmyService
 *
 * @author < a href=" ">BBB</ a>
 * @version v1.0.01
 * @date 2019-12-27 14:41
 */
@Service
public class ArmyService {
  @Autowired
  ArmyDao armyDao;

  public List<Army> findAllArmy() {
    return armyDao.findAll();
  }

  public Army findArmyById(String id) {
    return armyDao.findById(id).orElse(null);
  }

  public Response saveArmy(Army entity) {
    try {
      armyDao.save(entity);
      return new Response(ResponseCode.CODE_200, MessageConstants.SUCCESS);
    } catch (Exception e) {
      return new Response(ResponseCode.CODE_202, e.getMessage());
    }
  }

  public Response deleteArmyById(String id) {
    try {
      armyDao.deleteById(id);
      return new Response(ResponseCode.CODE_200, MessageConstants.SUCCESS);
    } catch (Exception e) {
      return new Response(ResponseCode.CODE_202, e.getMessage());
    }
  }
}
